package com.jxwifi.cloud.quickclean.popwindow;

import android.content.Context;
import android.content.Intent;
import android.text.Html;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jxwifi.cloud.quickclean.R;
import com.jxwifi.cloud.quickclean.main.MainUserActivity;
import com.popwindow.BasicPopmodule;

import butterknife.internal.DebouncingOnClickListener;

public class PopProtocol extends BasicPopmodule {

    private Context mContext;

    private PopProtocolListener mPoplistener;

    public PopProtocol(Context context, PopProtocolListener l){
        this.mContext=context;
        this.mPoplistener=l;
        initView();
    }

    @Override
    public void setPopwindow(PopupWindow pop) {
        mPopwindows = pop;
    }

    @Override
    public View getView() {
        return mContentView;
    }

    private void initView() {
        mContentView = LayoutInflater.from(mContext).inflate(R.layout.pop_protocol_module, new LinearLayout(mContext), false);
        setListener();
    }

    private void setListener() {
        RelativeLayout mDisagree=(RelativeLayout)mContentView.findViewById(R.id.pop_protocol_disagree);
        RelativeLayout mAgree=(RelativeLayout)mContentView.findViewById(R.id.pop_protocol_agree);

        SpannableStringBuilder spannableString = new SpannableStringBuilder();
        spannableString.append(Html.fromHtml("请你务必审慎阅读,充分理解\"服务协议\"和\"隐私政策\"各条款,包括但不限于:为了向你提供即时通讯,内容分享等服务,我们需要收集你的设备信息,操作日志等个人信息。你可以在\"设置\"中查看,变更,删除个人信息并管理你的授权。你可阅读<font color=\"#00AAFF\">《服务协议》</font>和<font color=\"#00AAFF\">《隐私政策》</font>了解详细信息。如你同意，请点击\"同意\"开始接受我们的服务"));
        /*UnderlineSpan underlineSpan = new UnderlineSpan();
        spannableString.setSpan(underlineSpan, 112, 118, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
        spannableString.setSpan(underlineSpan, 120, 126, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);*/
        ClickableSpan clickableSpan = new ClickableSpan() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(mContext, MainUserActivity.class);
                mContext.startActivity(intent);
            }
        };
        spannableString.setSpan(clickableSpan, 112, 118, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);

        ClickableSpan clickableSpan2 = new ClickableSpan() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(mContext, MainUserActivity.class);
                intent.putExtra("agreementId",2+"");
                mContext.startActivity(intent);
            }
        };
        spannableString.setSpan(clickableSpan2, 119, 125, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);

        TextView mTvTextTitle=(TextView)mContentView.findViewById(R.id.tv_pop_text_title);
        //mTvTextTitle.setText(Html.fromHtml("请你务必审慎阅读,充分理解\"服务协议\"和\"隐私政策\"各条款,包括但不限于:为了向你提供即时通讯,内容分享等服务,我们需要收集你的设备信息,操作日志等个人信息。你可以在\"设置\"中查看,变更,删除个人信息并管理你的授权。你可阅读<font color=\"#00AAFF\">《服务协议》</font>和<font color=\"#00AAFF\">《隐私政策》</font>了解详细信息。如你同意，请点击\"同意\"开始接受我们的服务"));
        mTvTextTitle.setText(spannableString);
        mTvTextTitle.setMovementMethod(LinkMovementMethod.getInstance());
        mDisagree.setOnClickListener(new DebouncingOnClickListener() {
            @Override
            public void doClick(View view) {
                mPoplistener.PopDisagree();
            }
        });
        mAgree.setOnClickListener(new DebouncingOnClickListener() {
            @Override
            public void doClick(View view) {
                mPoplistener.PopAgree();
            }
        });

    }

    public interface PopProtocolListener {
        void PopDisagree();
        void PopAgree();
    }
}
